package zone.haiwen.demo.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import zone.haiwen.demo.dto.Passenger;
import zone.haiwen.demo.dto.Travel;
import zone.haiwen.demo.service.TravelService;
import zone.haiwen.demo.util.JsonResult;
import zone.haiwen.demo.util.ResultCode;

/**
 * Description
 * @author zhangHaiWen
 * @date 2021/7/8 20:19
 * @return
 **/
@RestController
@RequestMapping("/test/travel")
public class TravelController {

    private final TravelService travelService;

    public TravelController(TravelService travelService) {
        this.travelService = travelService;
    }

    /**
     * Description
     * @author zhangHaiWen
     * @date 2021/7/8 20:40
     * @return zone.haiwen.demo.util.JsonResult
     **/
    @GetMapping("/createTable")
    public JsonResult crateTable(){
        this.travelService.createTable();
        return new JsonResult(ResultCode.SUCCESS);
    }

    /**
     * Description
     * @author zhangHaiWen
     * @date 2021/7/8 20:41
     * @return zone.haiwen.demo.util.JsonResult
     **/
    @GetMapping("/insert")
    public JsonResult insert(Long id, String destination, String passengerName, Long passengerId, String gmtCreate, String gmtModified){
        this.travelService.insert(id, destination, passengerName, passengerId, gmtCreate, gmtModified);
        return new JsonResult(ResultCode.SUCCESS);
    }

    /**
     * Description
     * @author zhangHaiWen
     * @date 2021/7/8 20:41
     * @return zone.haiwen.demo.util.JsonResult
     **/
    @GetMapping("/getTravelByDestination")
    public JsonResult getTravelByDestination(String destination, Integer current, Integer limit) {
        IPage<Travel> myTravel = this.travelService.getTravelByDestination(destination, current, limit);
        return new JsonResult(ResultCode.SUCCESS, myTravel);
    }

    /**
     * Description
     * @author zhangHaiWen
     * @date 2021/7/8 20:41
     * @return zone.haiwen.demo.util.JsonResult
     **/
    @GetMapping("/leftJoin")
    public JsonResult leftJoin(Integer current, Integer limit) {
        IPage<Passenger> myTravel = this.travelService.leftJoin(current, limit);
        return new JsonResult(ResultCode.SUCCESS, myTravel);
    }


}
